<?php namespace Admin\Controller;
use Hdphp\Libs\Controller;
use Hdphp\Tools\Code;
class LoginController extends Controller{
    public function index(){
        if(IS_POST){
            $username=$_POST['username'];
            $password=$_POST['password'];
            if(strlen(trim($username)) ==0||strlen(trim($password)) ==0){
                $this->error("用户名或密码不能为空");exit;
            }
            //验证用户名是否正确
            $data = M()->query("select * from user where username='{$username}'");
            if (!$data){
                $this->error("用户名不存在");exit;
            }
           // $data = M()->query("select * from user where password='{$password}'");

            if(md5($password) != $data[0]['password']){
                $this->error("密码错误");exit;
            }
            //如果 用户名密码都没有问题存session
            $_SESSION['uid'] = $data[0]['uid'];
            //跳转
            $this->success("登陆成功","index.php?m=Admin" );die;
        }
        $this->assign("title",'登陆页面');
        //框架App 里面定义的常量指向目录的根目录
        $this->assign("root",__ROOT__);
        $this->display();
    }
    public function code(){
        $code = new Code;
        $code->make();
    }
}
